package com.special.threademo.concurrency.waitNotify;

/**
 * Created with IDEA2020.3
 * author:LiuYC
 * DateTime:2021/1/7  11:59
 */
public class DeOrIncrease {
    private int counter;

    public synchronized void increase() {
        while (counter != 0) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        counter++;
        System.out.println(counter);
        notify();

    }

    public synchronized void decrease() {
        while (counter == 0) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        counter--;
        System.out.println(counter);
        notify();

    }
}
